# Maintainer: Sören Tempel <soeren+alpine@soeren-tempel.net>
pkgname=alacritty
pkgver=0.14.0
pkgrel=0
pkgdesc="cross-platform, GPU-accelerated terminal emulator"
url="https://github.com/alacritty/alacritty"
# s390x: incompatible with nix crate
arch="all !s390x"
license="Apache-2.0"
# libxi, libcursor, and libxkbcommon-x11 are loaded via dlopen by x11-rs and xkbcommon-dl crate.
depends="ncurses-terminfo-base wayland-libs-egl libxi libxcursor libxkbcommon-x11"
makedepends="
	cargo
	cargo-auditable
	cmake
	fontconfig-dev
	freetype-dev
	libxcb-dev
	libxkbcommon-dev
	python3
	rust
	scdoc
	"
subpackages="
	$pkgname-doc
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
options="net"
source="$pkgname-$pkgver.tar.gz::https://github.com/alacritty/alacritty/archive/refs/tags/v$pkgver.tar.gz"

prepare() {
	default_prepare

	cargo fetch --target="$CTARGET" --locked
}

build() {
	# Compile all man pages.
	local scd
	for scd in extra/man/*.scd; do
		scdoc < "$scd" > "${scd%.*}"
	done

	cargo auditable build --release --frozen
}

check() {
	cargo test --workspace --release --frozen
}

package() {
	install -Dm755 target/release/alacritty "$pkgdir"/usr/bin/alacritty

	# Install all man pages
	local f
	for f in extra/man/*.?; do
		install -Dm644 "$f" "$pkgdir"/usr/share/man/man${f##*.}/${f##*/}
	done

	# Install addition documentation files.
	install -Dm644 -t "$pkgdir"/usr/share/doc/$pkgname \
		README.md CHANGELOG.md docs/*

	# Install desktop files.
	install -Dm644 extra/linux/Alacritty.desktop -t "$pkgdir"/usr/share/applications
	install -Dm644 extra/logo/alacritty-term.svg \
		"$pkgdir"/usr/share/icons/hicolor/scalable/apps/Alacritty.svg
	install -Dm644 extra/linux/org.alacritty.Alacritty.appdata.xml \
		"$pkgdir"/usr/share/metainfo/org.alacritty.Alacritty.appdata.xml

	# Install completion files.
	install -Dm644 extra/completions/alacritty.bash \
		"$pkgdir"/usr/share/bash-completion/completions/"$pkgname"
	install -Dm644 extra/completions/alacritty.fish \
		"$pkgdir"/usr/share/fish/vendor_completions.d/"$pkgname".fish
	install -Dm644 extra/completions/_alacritty \
		"$pkgdir"/usr/share/zsh/site-functions/_"$pkgname"
}

sha512sums="
3001ca78b3f4b2a22076cb701108b77263962c1f4cb50a17219dfb0165d11a1f7b4e879af0358c1c7a5cca7949951169127e45603cfb74e932f14f2299f76962  alacritty-0.14.0.tar.gz
"
